#include <bits/stdc++.h>
using namespace std;
inline int read(){
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        s=s*10+ch-'0';
        ch=getchar();
    }
    return s*f;
}
const int N=2e5+20;
int T,n;
int a[N];

int dfs(int dep,int tot,int oe,int zr){
    
    if(dep>n) return tot;
    
    return max(dfs(dep+1,tot+(a[oe]==a[dep]?a[dep]:0),dep,zr),dfs(dep+1,tot+(a[zr]==a[dep]?a[dep]:0),oe,dep));

}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    T=read();
    while(T--){
        n=read();
        a[0]=0;
        for(int i=1;i<=n;i++){
            a[i]=read();
        }
        
        printf("%d\n",dfs(1,0,0,0));
    }
    return 0;
}
/*
3
3
1 2 1
4
1 2 3 4
8
3 5 2 5 1 2 1 4

*/